package com.cryptoneedle.garden.service.crud.garden.doris;

import com.cryptoneedle.garden.entity.garden.ads.AdsColumn;
import com.cryptoneedle.garden.entity.garden.ads.AdsTable;
import com.cryptoneedle.garden.entity.garden.doris.*;
import com.cryptoneedle.garden.entity.garden.dwd.DwdColumn;
import com.cryptoneedle.garden.entity.garden.dwd.DwdTable;
import com.cryptoneedle.garden.entity.garden.mapping.MappingColumn;
import com.cryptoneedle.garden.entity.garden.mapping.MappingJoin;
import com.cryptoneedle.garden.entity.garden.mapping.MappingTable;
import com.cryptoneedle.garden.entity.garden.ods.OdsColumn;
import com.cryptoneedle.garden.entity.garden.ods.OdsColumnTranslate;
import com.cryptoneedle.garden.entity.garden.ods.OdsTable;
import com.cryptoneedle.garden.key.*;
import com.cryptoneedle.garden.repository.garden.ads.AdsColumnRepository;
import com.cryptoneedle.garden.repository.garden.ads.AdsTableRepository;
import com.cryptoneedle.garden.repository.garden.doris.*;
import com.cryptoneedle.garden.repository.garden.dwd.DwdColumnRepository;
import com.cryptoneedle.garden.repository.garden.dwd.DwdTableRepository;
import com.cryptoneedle.garden.repository.garden.mapping.MappingColumnRepository;
import com.cryptoneedle.garden.repository.garden.mapping.MappingJoinRepository;
import com.cryptoneedle.garden.repository.garden.mapping.MappingTableRepository;
import com.cryptoneedle.garden.repository.garden.ods.OdsColumnRepository;
import com.cryptoneedle.garden.repository.garden.ods.OdsColumnTranslateRepository;
import com.cryptoneedle.garden.repository.garden.ods.OdsTableRepository;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>description:  </p>
 *
 * @author CryptoNeedle
 * @date 2025-11-13
 */
@Slf4j
@Service
@Transactional
public class FoundDorisService {

    @Autowired
    private FoundDorisService select;
    @Autowired
    private AddDorisService add;
    @Autowired
    private PatchDorisService patch;
    @Autowired
    private SaveDorisService save;
    @Autowired
    private DeleteDorisService delete;

    @Resource
    private DorisCatalogRepository dorisCatalogRepository;
    @Resource
    private DorisDatabaseRepository dorisDatabaseRepository;
    @Resource
    private DorisTableRepository dorisTableRepository;
    @Resource
    private MappingTableRepository mappingTableRepository;
    @Resource
    private OdsTableRepository odsTableRepository;
    @Resource
    private DwdTableRepository dwdTableRepository;
    @Resource
    private AdsTableRepository adsTableRepository;
    @Resource
    private DorisColumnRepository dorisColumnRepository;
    @Resource
    private MappingColumnRepository mappingColumnRepository;
    @Resource
    private OdsColumnRepository odsColumnRepository;
    @Resource
    private DwdColumnRepository dwdColumnRepository;
    @Resource
    private AdsColumnRepository adsColumnRepository;

    @Resource
    private MappingJoinRepository mappingJoinRepository;
    @Resource
    private OdsColumnTranslateRepository odsColumnTranslateRepository;
    @Resource
    private DorisTableScriptRepository dorisTableScriptRepository;

    /**
     * DorisCatalog
     */
    public DorisCatalog dorisCatalog(CatalogKey key) {
        return dorisCatalogRepository.findById(key).orElse(null);
    }

    public DorisCatalog dorisCatalog(String catalogName) {
        return select.dorisCatalog(new CatalogKey(catalogName));
    }

    public List<DorisCatalog> dorisCatalogs() {
        return dorisCatalogRepository.dorisCatalogs();
    }

    /**
     * DorisDatabase
     */
    public DorisDatabase dorisDatabase(DatabaseKey key) {
        return dorisDatabaseRepository.findById(key).orElse(null);
    }

    public DorisDatabase dorisDatabase(String catalogName, String databaseName) {
        return select.dorisDatabase(new DatabaseKey(catalogName, databaseName));
    }

    public List<DorisDatabase> dorisDatabases() {
        return dorisDatabaseRepository.dorisDatabases();
    }

    public List<DorisDatabase> dorisDatabases(String catalogName) {
        return dorisDatabaseRepository.dorisDatabases(catalogName);
    }

    public List<DorisDatabase> dorisDatabases(CatalogKey key) {
        return select.dorisDatabases(key.getCatalogName());
    }

    /**
     * DorisTable
     */
    public DorisTable dorisTable(TableKey key) {
        return dorisTableRepository.findById(key).orElse(null);
    }

    public DorisTable dorisTable(String catalogName, String databaseName, String tableName) {
        return select.dorisTable(new TableKey(catalogName, databaseName, tableName));
    }

    public List<DorisTable> dorisTables() {
        return dorisTableRepository.dorisTables();
    }

    public List<DorisTable> dorisTables(String catalogName) {
        return dorisTableRepository.dorisTables(catalogName);
    }

    public List<DorisTable> dorisTables(CatalogKey key) {
        return select.dorisTables(key.getCatalogName());
    }

    public List<DorisTable> dorisTables(String catalogName, String databaseName) {
        return dorisTableRepository.dorisTables(catalogName, databaseName);
    }

    public List<DorisTable> dorisTables(DatabaseKey key) {
        return select.dorisTables(key.getCatalogName(), key.getDatabaseName());
    }

    /**
     * MappingTable
     */
    public MappingTable mappingTable(TableKey key) {
        return mappingTableRepository.findById(key).orElse(null);
    }

    public MappingTable mappingTable(String catalogName, String databaseName, String tableName) {
        return select.mappingTable(new TableKey(catalogName, databaseName, tableName));
    }

    public List<MappingTable> mappingTables() {
        return mappingTableRepository.mappingTables();
    }

    public List<MappingTable> mappingTables(String catalogName) {
        return mappingTableRepository.mappingTables(catalogName);
    }

    public List<MappingTable> mappingTables(CatalogKey key) {
        return select.mappingTables(key.getCatalogName());
    }

    public List<MappingTable> mappingTables(String catalogName, String databaseName) {
        return mappingTableRepository.mappingTables(catalogName, databaseName);
    }

    public List<MappingTable> mappingTables(DatabaseKey key) {
        return select.mappingTables(key.getCatalogName(), key.getDatabaseName());
    }

    /**
     * OdsTable
     */
    public OdsTable odsTable(TableKey key) {
        return odsTableRepository.findById(key).orElse(null);
    }

    public OdsTable odsTable(String catalogName, String databaseName, String tableName) {
        return select.odsTable(new TableKey(catalogName, databaseName, tableName));
    }

    public List<OdsTable> odsTables() {
        return odsTableRepository.odsTables();
    }

    public List<OdsTable> odsTables(String catalogName) {
        return odsTableRepository.odsTables(catalogName);
    }

    public List<OdsTable> odsTables(CatalogKey key) {
        return select.odsTables(key.getCatalogName());
    }

    public List<OdsTable> odsTables(String catalogName, String databaseName) {
        return odsTableRepository.odsTables(catalogName, databaseName);
    }

    public List<OdsTable> odsTables(DatabaseKey key) {
        return select.odsTables(key.getCatalogName(), key.getDatabaseName());
    }

    /**
     * DwdTable
     */
    public DwdTable dwdTable(TableKey key) {
        return dwdTableRepository.findById(key).orElse(null);
    }

    public DwdTable dwdTable(String catalogName, String databaseName, String tableName) {
        return select.dwdTable(new TableKey(catalogName, databaseName, tableName));
    }

    public List<DwdTable> dwdTables() {
        return dwdTableRepository.dwdTables();
    }

    public List<DwdTable> dwdTables(String catalogName) {
        return dwdTableRepository.dwdTables(catalogName);
    }

    public List<DwdTable> dwdTables(CatalogKey key) {
        return select.dwdTables(key.getCatalogName());
    }

    public List<DwdTable> dwdTables(String catalogName, String databaseName) {
        return dwdTableRepository.dwdTables(catalogName, databaseName);
    }

    public List<DwdTable> dwdTables(DatabaseKey key) {
        return select.dwdTables(key.getCatalogName(), key.getDatabaseName());
    }

    /**
     * AdsTable
     */
    public AdsTable adsTable(TableKey key) {
        return adsTableRepository.findById(key).orElse(null);
    }

    public AdsTable adsTable(String catalogName, String databaseName, String tableName) {
        return select.adsTable(new TableKey(catalogName, databaseName, tableName));
    }

    public List<AdsTable> adsTables() {
        return adsTableRepository.adsTables();
    }

    public List<AdsTable> adsTables(String catalogName) {
        return adsTableRepository.adsTables(catalogName);
    }

    public List<AdsTable> adsTables(CatalogKey key) {
        return select.adsTables(key.getCatalogName());
    }

    public List<AdsTable> adsTables(String catalogName, String databaseName) {
        return adsTableRepository.adsTables(catalogName, databaseName);
    }

    public List<AdsTable> adsTables(DatabaseKey key) {
        return select.adsTables(key.getCatalogName(), key.getDatabaseName());
    }

    /**
     * DorisColumn
     */
    public DorisColumn dorisColumn(ColumnKey key) {
        return dorisColumnRepository.findById(key).orElse(null);
    }

    public DorisColumn dorisColumn(String catalogName, String databaseName, String tableName, String columnName) {
        return select.dorisColumn(new ColumnKey(catalogName, databaseName, tableName, columnName));
    }

    public List<DorisColumn> dorisColumns() {
        return dorisColumnRepository.dorisColumns();
    }

    public List<DorisColumn> dorisColumns(String catalogName) {
        return dorisColumnRepository.dorisColumns(catalogName);
    }

    public List<DorisColumn> dorisColumns(CatalogKey key) {
        return select.dorisColumns(key.getCatalogName());
    }

    public List<DorisColumn> dorisColumns(String catalogName, String databaseName) {
        return dorisColumnRepository.dorisColumns(catalogName, databaseName);
    }

    public List<DorisColumn> dorisColumns(DatabaseKey key) {
        return select.dorisColumns(key.getCatalogName(), key.getDatabaseName());
    }

    public List<DorisColumn> dorisColumns(String catalogName, String databaseName, String tableName) {
        return dorisColumnRepository.dorisColumns(catalogName, databaseName, tableName);
    }

    public List<DorisColumn> dorisColumns(TableKey key) {
        return select.dorisColumns(key.getCatalogName(), key.getDatabaseName(), key.getTableName());
    }

    /**
     * MappingColumn
     */
    public MappingColumn mappingColumn(ColumnKey key) {
        return mappingColumnRepository.findById(key).orElse(null);
    }

    public MappingColumn mappingColumn(String catalogName, String databaseName, String tableName, String columnName) {
        return select.mappingColumn(new ColumnKey(catalogName, databaseName, tableName, columnName));
    }

    public List<MappingColumn> mappingColumns() {
        return mappingColumnRepository.mappingColumns();
    }

    public List<MappingColumn> mappingColumns(String catalogName) {
        return mappingColumnRepository.mappingColumns(catalogName);
    }

    public List<MappingColumn> mappingColumns(CatalogKey key) {
        return select.mappingColumns(key.getCatalogName());
    }

    public List<MappingColumn> mappingColumns(String catalogName, String databaseName) {
        return mappingColumnRepository.mappingColumns(catalogName, databaseName);
    }

    public List<MappingColumn> mappingColumns(DatabaseKey key) {
        return select.mappingColumns(key.getCatalogName(), key.getDatabaseName());
    }

    public List<MappingColumn> mappingColumns(String catalogName, String databaseName, String tableName) {
        return mappingColumnRepository.mappingColumns(catalogName, databaseName, tableName);
    }

    public List<MappingColumn> mappingColumns(TableKey key) {
        return select.mappingColumns(key.getCatalogName(), key.getDatabaseName(), key.getTableName());
    }

    /**
     * OdsColumn
     */
    public OdsColumn odsColumn(ColumnKey key) {
        return odsColumnRepository.findById(key).orElse(null);
    }

    public OdsColumn odsColumn(String catalogName, String databaseName, String tableName, String columnName) {
        return select.odsColumn(new ColumnKey(catalogName, databaseName, tableName, columnName));
    }

    public List<OdsColumn> odsColumns() {
        return odsColumnRepository.odsColumns();
    }

    public List<OdsColumn> odsColumns(String catalogName) {
        return odsColumnRepository.odsColumns(catalogName);
    }

    public List<OdsColumn> odsColumns(CatalogKey key) {
        return select.odsColumns(key.getCatalogName());
    }

    public List<OdsColumn> odsColumns(String catalogName, String databaseName) {
        return odsColumnRepository.odsColumns(catalogName, databaseName);
    }

    public List<OdsColumn> odsColumns(DatabaseKey key) {
        return select.odsColumns(key.getCatalogName(), key.getDatabaseName());
    }

    public List<OdsColumn> odsColumns(String catalogName, String databaseName, String tableName) {
        return odsColumnRepository.odsColumns(catalogName, databaseName, tableName);
    }

    public List<OdsColumn> odsColumns(TableKey key) {
        return select.odsColumns(key.getCatalogName(), key.getDatabaseName(), key.getTableName());
    }

    /**
     * DwdColumn
     */
    public DwdColumn dwdColumn(ColumnKey key) {
        return dwdColumnRepository.findById(key).orElse(null);
    }

    public DwdColumn dwdColumn(String catalogName, String databaseName, String tableName, String columnName) {
        return select.dwdColumn(new ColumnKey(catalogName, databaseName, tableName, columnName));
    }

    public List<DwdColumn> dwdColumns() {
        return dwdColumnRepository.dwdColumns();
    }

    public List<DwdColumn> dwdColumns(String catalogName) {
        return dwdColumnRepository.dwdColumns(catalogName);
    }

    public List<DwdColumn> dwdColumns(CatalogKey key) {
        return select.dwdColumns(key.getCatalogName());
    }

    public List<DwdColumn> dwdColumns(String catalogName, String databaseName) {
        return dwdColumnRepository.dwdColumns(catalogName, databaseName);
    }

    public List<DwdColumn> dwdColumns(DatabaseKey key) {
        return select.dwdColumns(key.getCatalogName(), key.getDatabaseName());
    }

    public List<DwdColumn> dwdColumns(String catalogName, String databaseName, String tableName) {
        return dwdColumnRepository.dwdColumns(catalogName, databaseName, tableName);
    }

    public List<DwdColumn> dwdColumns(TableKey key) {
        return select.dwdColumns(key.getCatalogName(), key.getDatabaseName(), key.getTableName());
    }

    /**
     * AdsColumn
     */
    public AdsColumn adsColumn(ColumnKey key) {
        return adsColumnRepository.findById(key).orElse(null);
    }

    public AdsColumn adsColumn(String catalogName, String databaseName, String tableName, String columnName) {
        return select.adsColumn(new ColumnKey(catalogName, databaseName, tableName, columnName));
    }

    public List<AdsColumn> adsColumns() {
        return adsColumnRepository.adsColumns();
    }

    public List<AdsColumn> adsColumns(String catalogName) {
        return adsColumnRepository.adsColumns(catalogName);
    }

    public List<AdsColumn> adsColumns(CatalogKey key) {
        return select.adsColumns(key.getCatalogName());
    }

    public List<AdsColumn> adsColumns(String catalogName, String databaseName) {
        return adsColumnRepository.adsColumns(catalogName, databaseName);
    }

    public List<AdsColumn> adsColumns(DatabaseKey key) {
        return select.adsColumns(key.getCatalogName(), key.getDatabaseName());
    }

    public List<AdsColumn> adsColumns(String catalogName, String databaseName, String tableName) {
        return adsColumnRepository.adsColumns(catalogName, databaseName, tableName);
    }

    public List<AdsColumn> adsColumns(TableKey key) {
        return select.adsColumns(key.getCatalogName(), key.getDatabaseName(), key.getTableName());
    }

    /**
     * MappingJoin
     */
    public MappingJoin mappingJoin(JoinKey key) {
        return mappingJoinRepository.findById(key).orElse(null);
    }

    public List<MappingJoin> mappingJoins(String primaryCatalogName, String primaryDatabaseName) {
        return mappingJoinRepository.mappingJoins(primaryCatalogName, primaryDatabaseName);
    }

    public List<MappingJoin> mappingJoins(String primaryCatalogName, String primaryDatabaseName, String primaryTableName) {
        return mappingJoinRepository.mappingJoins(primaryCatalogName, primaryDatabaseName, primaryTableName);
    }

    public List<MappingJoin> mappingJoinsByMapping(String joinCatalogName, String joinDatabaseName, String joinTableName) {
        return mappingJoinRepository.mappingJoinsByJoin(joinCatalogName, joinDatabaseName, joinTableName);
    }

    /**
     * OdsColumnTranslate
     */
    public OdsColumnTranslate odsColumnTranslate(OdsColumnTranslateKey key) {
        return odsColumnTranslateRepository.findById(key).orElse(null);
    }

    public List<OdsColumnTranslate> odsColumnTranslates(String catalogName, String databaseName) {
        return odsColumnTranslateRepository.odsColumnTranslates(catalogName, databaseName);
    }

    public List<OdsColumnTranslate> odsColumnTranslates(String catalogName, String databaseName, String tableName) {
        return odsColumnTranslateRepository.odsColumnTranslates(catalogName, databaseName, tableName);
    }

    public List<OdsColumnTranslate> odsColumnTranslates(String catalogName, String databaseName, String tableName, String columnName) {
        return odsColumnTranslateRepository.odsColumnTranslates(catalogName, databaseName, tableName, columnName);
    }

    /**
     * DorisTableScript
     */
    public DorisTableScript dorisTableScript(TableKey key) {
        return dorisTableScriptRepository.findById(key).orElse(null);
    }

    public List<DorisTableScript> dorisTableScripts(String catalogName) {
        return dorisTableScriptRepository.dorisTableScripts(catalogName);
    }

    public List<DorisTableScript> dorisTableScripts(String catalogName, String databaseName) {
        return dorisTableScriptRepository.dorisTableScripts(catalogName, databaseName);
    }
}